import Vue from 'vue'
import Router from 'vue-router'
import  Index     from   './views/index.vue'
import  Login     from   './views/login.vue'
Vue.use(Router)

const  router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    //默认的路由
    {
        path:'/index',
        name:'index',
        component:Index
    },
    //登陆的路由
    {
      path:'/login',
      name:'index',
      component:Login 
  }
  ],
})
// 路由守卫
router.beforeEach((to, from, next) => {
  const isLogin = localStorage.ele_login ? true : false;
  if (to.path == '/login') {
    next();
  } else {
    // 是否在登录状态下
    isLogin ? next() : next('/login');
  }
});

export default router;
